package com.example.democonfigserver.modules.project;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author wangbin
 */
@RestController
@RequestMapping("/project")
@Validated
public class ProjectController {
    @Resource
    private ProjectRepository projectRepository;

    @GetMapping
    public Page<Project> pageList(Pageable pageable) {
        return projectRepository.findAll(pageable);
    }

    @GetMapping("/{id}")
    public Project getOne(@PathVariable Integer id) {
        return projectRepository.getOne(id);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        projectRepository.deleteById(id);
    }

    @PostMapping
    public void save(@RequestBody @Valid Project project) {
        projectRepository.save(project);
    }
}
